package com.example.springboot.controller;

import com.example.springboot.pojo.Result;
import com.example.springboot.service.FileService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/files")
@CrossOrigin(origins = "*")
public class FileController {

    @Autowired
    private FileService fileService;

    @PostMapping("/uploadFile")
    public Result<?> uploadFile(MultipartFile file) throws IOException {
        String url = fileService.uploadFile(file);
        return Result.success(url);
    }

    @GetMapping("/{flag}")
    public void getFiles(@PathVariable String flag,HttpServletResponse response){
        fileService.getFile(flag,response);
    }

    @PutMapping("/deleteFile")
    public void DeleteFile(String url){
        fileService.deleteFile(url);
    }
}
